package org.zhouhe.web.tag.function;

public class FmtBodyFunction {
	private String funName;
	private String tagBody;
	public FmtBodyFunction(String funName, String tagBody){
		this.funName = funName;
		this.tagBody = tagBody;
	}
	@Override
	public String toString() {
		StringBuilder fun = new StringBuilder();
		fun.append("\r\n  function "+ funName +"(val, rowData){");
		fun.append("\r\n    var str='"+ tagBody.replaceAll("'", "\\'").replaceAll("\r\n", "") +"';");
		fun.append("\r\n    for(var k in rowData){");
		fun.append("\r\n      str = str.replace(new RegExp('#'+k+'#','gm'), rowData[k]);");
		fun.append("\r\n    };");
		fun.append("\r\n    return str;");
		fun.append("\r\n  }");
		return fun.toString();
	}
}
